package com.concurrence;
/**
 * SafeDemo..
 *
 * @author Lizhong
 * @date 2019/3/30
 */
public class SafeDemo {
    int a = 0;
    boolean delflag = false;

    public synchronized void w() {
        this.a = 2;
        this.delflag = true;
    }

    public synchronized void r() {
        boolean delFlag = this.delflag;
        int i = this.a * this.a;
        System.out.println(i);
        System.out.println(delFlag);
        if (delFlag) {
            System.out.println(this.a*this.a+"*****");
        }
    }

    public static void main(String[] args) throws InterruptedException {
        int i=0;
         // while (i<100){
            SafeDemo volatileDemo = new SafeDemo();
            Thread thread = new Thread(volatileDemo::w);
            Thread thread1 = new Thread(volatileDemo::r);
            thread.start();
            thread1.start();

            // i++;}
        Thread.sleep(500);
    }
}
